// nav的固定与变色--pc端使用
setInterval(() => {
  const header = document.querySelector('#head_pc .Nav')

  if (window.innerWidth > 768) {

    (function () {
      const n = document.documentElement.scrollTop
      if (n > header.offsetHeight) {
        header.style.backgroundColor = '#7545A9'
        header.style.height = '130px'
      }
      else {
        header.style.height = '230px'
        header.style.background = 'linear-gradient(180deg, #7545A9 0%, rgba(117, 69, 169, 0) 100%)'
      }
    })();
  } else {
    header.style.height = '75px'
    header.style.backgroundColor = '#7545A9'
  }
}, 100);


// PC端swiper
(function () {
  const data = [
    { src: 'imgs/home/11.swiper.png', time: '2024.05.24', title: '郑州师范学院2023年河南省各类分数统计' },
    { src: 'imgs/home/11.swiper2.png', time: '2024.06.20', title: '校长张铟检查指导我校本科二批次高招录取工作' },
    { src: 'imgs/home/11.swiper3.png', time: '2024.06.18', title: '凝心聚力、携手并进，推动招生工作再上新台阶——我校召开2024年招生工作会议' }
  ]

  const img = document.querySelector('.content1 .MyImg')
  const time = document.querySelector('.content1 .swiper .bottom .content span')
  const title = document.querySelector('.content1 .swiper .bottom .content p')
  const btnPrev = document.querySelector('.content1 .swiper .bottom .pre')
  const btnNext = document.querySelector('.content1 .swiper .bottom .next')

  // 点击切换
  let i = 0
  btnNext.addEventListener('click', () => {
    i++
    i >= data.length && (i = 0)
    // 渲染
    toggle()
  })

  btnPrev.addEventListener('click', () => {
    i--
    i < 0 && (i = data.length - 1)
    // 渲染
    toggle()
  })

  // 渲染
  function toggle() {
    console.log(img.src);
    img.src = data[i].src
    time.innerHTML = data[i].time
    title.innerHTML = data[i].title
  }

  // 自动轮播
  let timerId = setInterval(function () {
    // 利用js自动调用点击事件
    btnNext.click()
  }, 5000)

  // 鼠标经过大盒子，停止计时器
  const slider = document.querySelector('.slider')
  slider.addEventListener('mouseenter', function () {
    // 停止定时器
    clearInterval(timerId)
  })

  // 鼠标离开大盒子，开启定时器
  slider.addEventListener('mouseleave', function () {
    // 停止定时器
    clearInterval(timerId)
    timerId = setInterval(function () {
      // 利用js自动调用点击事件
      btnNext.click()
    }, 5000)
  })
})();

// 初始化swiper
(function () {
  var swiper = new Swiper(".mySwiper", {
    slidesPerView: 3,
    spaceBetween: 30,
    pagination: {
      el: ".swiper-pagination",
      clickable: true,
    },
  });

  const progressCircle = document.querySelector(".autoplay-progress svg");
  const progressContent = document.querySelector(".autoplay-progress span");


})();


